<template>
  <div>
    <h1>添加电影</h1>
    <p>电影名:<input type="text" v-model="movies_name"></p>
    <p>上映时间:<input type="text" v-model="add_time"></p>
    <p>演员
        <select v-model="actor" >
            <option :value="i.id" v-for="i in actor_list" :key='i.id'>{{i.actor}}</option>
        </select>
    </p>
    <p>图片:<input type="file" id='img'></p>
    <input type="button" value="添加" @click="sub">
  </div>
</template>

<script>
export default {

  data () {
    return {
        movies_name:'',
        add_time:'',
        actor:[],
        actor_list:[],

    }
  },

  methods: {
      sub(){
          var img=document.getElementById('img').files[0]
          let form_data=new FormData()
          form_data.append('movies_name',this.movies_name)
          form_data.append('add_time',this.add_time)
          form_data.append('actor',this.actor)
          form_data.append('img',img)
          this.axios({
              url:'http://127.0.0.1:8000/app01/movies/',
              method:'post',
              data:form_data
          }).then(res=>{
              console.log(res)
          })
      }
  },
  created(){
      this.axios({
          url:'http://127.0.0.1:8000/app01/actor/',
          method:'get'
      }).then(res=>{
          console.log(res)
          this.actor_list=res.data
      })
  }
}
</script>

<style>

</style>